import numpy as np
import matplotlib.pyplot as plt


def pow_demo1():
    """
    幂函数
    :return:
    """
    x = np.linspace(-np.pi, 2 * np.pi, num=50)
    # y = x 的二次方  y1 等价于 y2
    y1 = x ** 2
    y2 = np.power(x, 2)

    plt.scatter(x, y1)
    plt.plot(x, y2)

    plt.axvline(0)
    plt.axhline(0)

    plt.show()


def pow_demo2():
    """
    指数函数
    :return:
    """
    x = np.linspace(-np.pi, 2 * np.pi, num=50)

    # y = 2 的x次方 y1 等价于 y2
    y1 = 2 ** x;
    y2 = np.power(2, x);

    plt.scatter(x, y1)
    plt.plot(x, y2)

    plt.axvline(0)
    plt.axhline(0)

    plt.show()


def log_demo1():
    """
    对数函数

    :return:
    """
    x = np.linspace(-np.pi, 2 * np.pi, num=50)

    # y = 2 的x次方
    y = np.log2(x);

    plt.scatter(x, y)
    plt.plot(x, y)

    plt.axvline(0)
    plt.axhline(0)

    plt.show()


def exp_demo1():
    """
    函数是求e x次方的值的函数。
    :return:
    """
    x = np.linspace(0, 2, num=50)
    y = np.exp(x ** 0.5)

    plt.plot(x, y)
    plt.fill_between(x, 0, y, color='k', alpha=0.4)
    plt.show()


if __name__ == '__main__':
    # pow_demo1()
    # pow_demo2()
    # log_demo1()
    exp_demo1()
